import {
  JsonController,
  Controller,
  Render,
  Get,
  UseBefore,
  Session,
  Req,
  Res,
  Ctx,
  QueryParams,
  UseInterceptor,
  Post,
  Body,
  Params,
} from "routing-controllers";
import { config } from "../../config";
import { Service, Inject } from "typedi";
import { HomeServiceImpl } from "../../service/impl/HomeServiceImpl";
import TokenLoginMiddlewares from "../../middleware/TokenLoginMiddlewares";
import { JsonResponseInterceptor } from "../../middleware/JsonResponseMiddlewares";
import { CollectionThinkModel, HomeDataModel, LikeThinkModel,ThinkInfoModel,setRecentVisitModel } from "../../model/HomeModel";
@Service()
@JsonController(`${config.apiurl}/v1/home`)
@UseInterceptor(JsonResponseInterceptor)
export class HomeControllerApi {
  @Inject()
  private HomeServiceImpl!: HomeServiceImpl;

  @Get("/getHomeData")
  @UseBefore(TokenLoginMiddlewares)
  public async getHomeData(
    @Res() response: any,
    @Session() session: any,
    @QueryParams() params: HomeDataModel
  ): Promise<any> {
    return await this.HomeServiceImpl.getAllHomeData(params);
  }

  @Get("/isLoginDelete")
  public async isLoginDelete(
    @Res() response: any,
    @Session() session: any
  ): Promise<any> {
    response.message = "登录失效";
    return;
  }

  @Get("/isLikeThink")
  @UseBefore(TokenLoginMiddlewares)
  public async isLikeThink(
    @Res() response: any,
    @Session() session: any,
    @QueryParams() params: LikeThinkModel
  ): Promise<any> {
    return await this.HomeServiceImpl.changeLikeThink(params);
  }

  @Get("/isCollectionThink")
  @UseBefore(TokenLoginMiddlewares)
  public async isCollectionThink(
    @Res() response: any,
    @Session() session: any,
    @QueryParams() params: CollectionThinkModel
  ): Promise<any> {
      console.log(params);
    return await this.HomeServiceImpl.changeCollectionThink(params);
  }


  @Get("/getThinkInfo")
  @UseBefore(TokenLoginMiddlewares)
  public async getThinkInfo(
    @Res() response: any,
    @Session() session: any,
    @QueryParams() params: ThinkInfoModel
  ): Promise<any> {
      console.log(await this.HomeServiceImpl.getThinkInfo(params))
     return await this.HomeServiceImpl.getThinkInfo(params);
  }

  @Get("/setRecentVisit")
  public async setRecentVisit (@Res() response: any,@Req() request:any, @Session() session:any,@QueryParams() params:setRecentVisitModel): Promise<any> {

    return await this.HomeServiceImpl.setRecentVisit(params);
      
    
  }
}
